home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / CLISRV / BOOKSALE / SERVER / SALES.CLS < prev    next >
Encoding:
Visual Basic class definition  |  1996-12-06  |  7.0 KB  |  244 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Sales"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Option Explicit
  11.  
  12. Dim sngPubRevenue() As Single     ' Array of monthly revenue amounts
  13. Dim sngAuthorRoyalty() As Single  ' Array of monthly royalty amounts
  14. Dim sngBookPrice() As Single        ' Array of monthly book prices
  15.  
  16. Public Function GetAuthors() As Variant
  17. 'This routine returns the complete list of known authors.  It is provided as a service to clients
  18. 'so that they do not need to know how or where to get the data themselves.  As such, it behaves
  19. 'as a "Data Service".  Normally, Data Services would be grouped separately from Business
  20. 'Services to help avoid development and maintenance dependencies.
  21.  
  22. End Function
  23. Public Function GetBooks(rstrAuthor As String) As Variant
  24. 'This routine returns the list of books the specified author has published.  It is provided as a service
  25. 'to clients so that they do not need to know how or where to get the data themselves.  As such, it
  26. 'behaves as a "Data Service".  Normally, Data Services would be grouped separately from Business
  27. 'Services to help avoid development and maintenance dependencies.
  28.  
  29. End Function
  30.  
  31. Public Function GetRevenue(intSalesModel As Integer, _
  32.                               curCostPerUnit As Currency, _
  33.                               curAdvCost As Currency, _
  34.                               intSalesPeriod As Integer, _
  35.                               lngUnitsPerMonth As Long, _
  36.                               bolIsDiscount As Boolean, _
  37.                               strBookTitle As String) As Variant
  38.  
  39.   Dim i As Integer
  40.   Dim iOldBound As Integer
  41.   Dim iNewBound As Integer
  42.  
  43.   gintSalesModel = intSalesModel
  44.   gcurCostPerUnit = curCostPerUnit
  45.   gcurAdvertisingCost = curAdvCost
  46.   gintSalesPeriod = intSalesPeriod
  47.   glngUnitsPerMonth = lngUnitsPerMonth
  48.   
  49.   If GetPubRevenue(strBookTitle) = False Then
  50.       ServerMsg Error$ & " - " & Str$(Err), vbOKOnly, "GetChartData Error"
  51.     GetRevenue = 0
  52.     Exit Function
  53.   
  54.   End If
  55.  
  56.   If GetAuthorRoyalty() = False Then
  57.       ServerMsg Error$ & " - " & Str$(Err), vbOKOnly, "GetChartData Error"
  58.     GetRevenue = 0
  59.     Exit Function
  60.  
  61.   End If
  62.  
  63.   iOldBound = UBound(sngPubRevenue)
  64.  
  65.   For i = 0 To iOldBound
  66.     sngPubRevenue(i, 1) = sngAuthorRoyalty(i)
  67.   
  68.   Next i
  69.  
  70.   GetRevenue = sngPubRevenue()
  71.  
  72. End Function
  73.  
  74. Public Function GetAuthorRoyalty() As Boolean
  75. Dim i As Integer
  76.  
  77. Dim cGrossMonthlySalary As Currency
  78. Dim cTaxAmount As Currency
  79. Dim cTotalRevenue As Currency
  80.  
  81. 'Create reference to Tax Class
  82. Dim objTax As New Taxes
  83.  
  84. frmBookSales.lblStatus(1).Caption = "Request Author Royalty..."
  85.  
  86. ReDim sngAuthorRoyalty(gintSalesPeriod)
  87.  
  88.   For i = 0 To (gintSalesPeriod - 1)
  89.     cGrossMonthlySalary = sngPubRevenue(i, 0) * gRoyalty
  90.     sngAuthorRoyalty(i) = cGrossMonthlySalary - _
  91.                                     objTax.CalcNationalIncomeTax(cGrossMonthlySalary) - _
  92.                                     objTax.CalcSalesTax(cGrossMonthlySalary, 0)
  93.  
  94.   Next i
  95.  
  96.   ' Delete Class Reference
  97.   Set objTax = Nothing
  98.   
  99.   frmBookSales.lblStatus(1).Caption = "Calculating Author Royalty..."
  100.   GetAuthorRoyalty = True
  101.  
  102. End Function
  103.  
  104. Public Function GetPubRevenue(strTitle As String) As Variant
  105. Dim sn As Recordset
  106. Dim strSQL As String
  107. Dim i As Integer
  108. Dim Price As Currency
  109.  
  110. 'Create Class References
  111. Dim objModel As New Model
  112.  
  113. Static strOldTitle As String
  114. Static cUnitPrice As Currency
  115.  
  116. frmBookSales.lblStatus(0).Caption = "Request Publisher Revenue..."
  117. frmBookSales.lblStatus(1).Caption = "Calculating Publisher Revenue..."
  118.  
  119. On Error GoTo GetRevenueError
  120.  
  121. If strTitle <> strOldTitle Then
  122.   frmBookSales.lblStatus(1).Caption = "Fetching row " & strTitle & "..."
  123.   strSQL = "SELECT Titles.Price " & _
  124.                 "FROM Titles " & _
  125.                 "WHERE ((Titles.Title=" & Chr$(34) & strTitle & Chr$(34) & "));"
  126.   
  127.   Set sn = gDB.OpenRecordset(strSQL, dbOpenSnapshot)
  128.   cUnitPrice = sn.Fields("Price")
  129.   
  130. Else
  131.   frmBookSales.lblStatus(1).Caption = "Using last values..."
  132.   
  133. End If
  134.  
  135. ReDim sngPubRevenue(gintSalesPeriod - 1, 1)
  136. ReDim sngBookPrice(gintSalesPeriod - 1)
  137.  
  138. For i = 0 To gintSalesPeriod - 1
  139.    sngPubRevenue(i, 0) = cUnitPrice * _
  140.                           objModel.intGetMonthSales(i, _
  141.                           gintSalesPeriod, _
  142.                           gintSalesModel)
  143. Next i
  144.  
  145. 'Delete Class Reference
  146. Set objModel = Nothing
  147.  
  148. frmBookSales.lblStatus(1).Caption = "Sending publisher revenue to client..."
  149. GetPubRevenue = True
  150.  
  151. ' Don't try to close the object if we never created the snapshot.
  152. ' sn is never defined when strTitle = strOldTitle.
  153.   If strTitle <> strOldTitle Then
  154.     sn.Close
  155.     Set sn = Nothing
  156.   End If
  157.  
  158.   strOldTitle = strTitle
  159.  
  160.   Exit Function
  161.   If IsObject(sn) Then sn.Close
  162.   Set sn = Nothing
  163.  
  164. GetRevenueError:
  165.   frmBookSales.lblStatus(1).Caption = Error$ & " - " & Str$(Err)
  166.   GetPubRevenue = False
  167.   
  168. End Function
  169.  
  170. Private Sub Class_Initialize()
  171.   
  172. On Error GoTo InitErr
  173.   
  174.   If gintInstanceCount = 0 Then
  175.     frmBookSales.Show
  176.     gintInstanceCount = 0
  177.     gDBName = App.Path & "\booksale.mdb"
  178.     
  179.     frmBookSales.lblStatus(1).Caption = "Creating Workspace..."
  180.     DoEvents
  181.     
  182.     Set gWkspc = Workspaces(0)
  183.     
  184.     frmBookSales.lblStatus(1).Caption = "opening " & gDBName & "..."
  185.     Set gDB = gWkspc.OpenDatabase(gDBName, False)
  186.     frmBookSales.lblStatus(1).Caption = "Awaiting command..."
  187.   End If
  188.     
  189.   gintInstanceCount = gintInstanceCount + 1
  190.   frmBookSales.lblInstanceCount.Caption = Format$(gintInstanceCount)
  191.  
  192.   Exit Sub
  193.  
  194. InitExit:
  195. Screen.MousePointer = vbDefault
  196. Exit Sub
  197.   
  198. InitErr:
  199.   
  200.   frmBookSales.lblStatus(1).Caption = Error$ & " - " & Str$(Err)
  201.   
  202.   'advanced error handling is required if the database cannot be
  203.   'found as error 3024 would indicate.
  204.   If Err = 3024 Then
  205.       'set CommonDialog properties before showing
  206.       With frmBookSales.CommonDialog1
  207.         .DialogTitle = "Unable to find the booksale.mdb file location"
  208.         .Filter = "(*.mdb)|*.mdb"
  209.         .InitDir = CurDir
  210.         .filename = ""
  211.         .Flags = cdlOFNExplorer Or cdlOFNFileMustExist Or cdlOFNPathMustExist
  212.         .ShowOpen
  213.         'make sure the filename is not an empty string
  214.         If .filename <> "" Then
  215.           'make sure that the database file returned is indeed booksale.mdb
  216.           If Right(UCase(.filename), Len("booksale.mdb")) = "BOOKSALE.MDB" Then
  217.             gDBName = .filename
  218.             Set gWkspc = Workspaces(0)
  219.           End If
  220.           Resume
  221.         End If
  222.       End With
  223.   ElseIf Err <> 0 Then ' another error
  224.       ServerMsg Error$ & " - " & Str$(Err), vbCritical, "BookSale Server Startup Error"
  225.       End
  226.   End If
  227.   
  228.   Resume InitExit
  229.   
  230. End Sub
  231.  
  232.  
  233.  
  234. Private Sub Class_Terminate()
  235.   gintInstanceCount = gintInstanceCount - 1
  236.   frmBookSales.lblInstanceCount.Caption = Format$(gintInstanceCount)
  237.   
  238.   If gintInstanceCount = 0 Then
  239.     Unload frmBookSales
  240.   End If
  241. End Sub
  242.  
  243.  
  244.